<?php 
/**
 * @author virowinsun <virowinsun@sohu-inc.com>
 * @version 1.0
 */
class Biz_SphinxSearch extends Lib_SphinxSearch{

    const WEIGHT    = 0 ;
    const COUNT   = 1 ;
    const INPUTDATE   = 2 ;
    const PRICE   = 3 ;
    const SORT_ASC  = 0 ;
    const SORT_DESC = 1 ;

    /**
     * 设置选项
     */
    public  $setting  = array();
    public  $sortmode = SPH_SORT_EXTENDED ;
    public  $filter   = array() ;
    public  $filterArray = array() ;
    private $order    = self::INPUTDATE ;
    private $sort     = self::SORT_DESC ;

    public function __construct(){
        parent::__construct();
        $this->port = '9318';
        $this->host = '10.11.5.206';
    }
    /**
     * 设置偏移量
     */
    public function setLimits($offset, $limit=0){
        $this->limit = 0;
        $this->offset = 0;
        if($limit){
            $this->limit = $limit ;
        }
        if($offset){
            $this->offset = $offset ;
        }
    }
    /**
     * 设置排序方式
     */
    public function setOrder($order){
        $this->order = $order ;
    }
    /**
     * 设置排序方向
     */
    public function setSort($sort){
        $this->sort = $sort ;
    }
    /**
     * 搜索产品，并取得结果，然后排序
     */
    public function searchPlayer($keyWord = '',$type = 1,$filter = array(),$mode = 1){
        $this->_getSortBy() ;
        $index = '*';
        return $this->searchBySphinx($keyWord, $index, $this->filterArray, $mode, array(), 1);
    }
    /**
     * 得到排序方法
     */
    private function _getSortBy(){
        switch ($this->sortby){
            case self::WEIGHT: $this->sortby = ' @weight ' ;break;
            default:$this->sortby = ' @weight ';break;
        }
        if($this->sort == self::SORT_ASC){
            $this->sortby .= ' asc ' ;
        }else{
            $this->sortby .= ' desc ' ;
        }
    }

    public function setFilter(Array $filter){
        $this->filterArray[] = $filter ;
    }

}
